/*!
 * \file UapEventConnectionReq.h
 * \brief Event carrying message UapConnectionReq
 */

#ifndef SGW_UAP_EVENT_CONNECTION_REQ_H
#define SGW_UAP_EVENT_CONNECTION_REQ_H

#include "EventData.h"
#include "UapGlobals.h"
#include "UAP.pb.h"

namespace tsc
{
namespace sgw
{

using UserApplicationPart::UapConnectionRequest;
using ProtocolsCommon::IpAddress;
using UserApplicationPart::ClientCapabilities;

/**
 * The first event which is handled by UapGenerator after being created.
 * It carries received UapConnectionReq message
 */
class UapEventConnectionReq : public common::EventData
{
public:

	UapEventConnectionReq(UapConnectionRequest& connReq,
	                      unsigned int socketConnId) :
		EventData(UAP_CONNECTION_REQ),
		mpClientIpAddress(0),
		mClientUapPort(0),
		mpClientCapabilities(0),
		mSocketConnId(socketConnId)
	{
		mpClientIpAddress = new IpAddress(connReq.sourceip());
		mClientUapPort = connReq.randomaccessport();
		if(connReq.has_capabilities())
		{
			mpClientCapabilities = new ClientCapabilities(connReq.capabilities());
		}
	}

	virtual ~UapEventConnectionReq()
	{
		delete mpClientIpAddress;
		delete mpClientCapabilities;
	}

	IpAddress* getClientIpAddress() const
	{
		return mpClientIpAddress;
	}

	uint32_t getClientUapPort() const
	{
		return mClientUapPort;
	}

	bool hasClientCapabilities() const
	{
		return mpClientCapabilities != 0;
	}

	ClientCapabilities* getClientCapabilities() const
	{
		return mpClientCapabilities;
	}

	unsigned int getSocketConnId() const
	{
	    return mSocketConnId;
	}

private:
	IpAddress*          mpClientIpAddress;
	uint32_t            mClientUapPort;
	ClientCapabilities* mpClientCapabilities;
	unsigned int        mSocketConnId;
};

} // namespace sgw
} // namespace tsc

#endif // SGW_UAP_EVENT_CONNECTION_REQ_H
